/*
 * sht20.h
 *
 *  Created on: May 10, 2023
 *      Author: lenovo lianxiang
 */

#ifndef INC_SHT20_H_
#define INC_SHT20_H_

#include "stm32l4xx_hal.h"


#define SHT20_ADDR 0x40

#define SHT20_ADDR_WR (SHT20_ADDR<<1)
#define SHT20_ADDR_RD ((SHT20_ADDR<<1) | 0x01)

#define TRH_FAIL_VAL      0xFFFFFFFF

enum
{
	TRIG_T_MEASUREMENT_HM    = 0xE3, // command trig. temp meas. hold master
	TRIG_RH_MEASUREMENT_HM   = 0xE5, // command trig. humidity meas. hold master
	TRIG_T_MEASUREMENT_POLL  = 0xF3, // command trig. temp meas. no hold master
	TRIG_RH_MEASUREMENT_POLL = 0xF5, // command trig. humidity meas. no hold master
	USER_REG_W               = 0xE6, // command writing user register
	USER_REG_R               = 0xE7, // command reading user register
	SOFT_RESET               = 0xFE  // command soft reset
};

extern uint32_t sht20_sample_TrH(uint32_t *temperature, uint32_t *humidity);

#endif /* INC_SHT20_H_ */




/*
 * sht20.h
 *
 *  Created on: May 23, 2023
 *      Author: Terrell
 */

#ifndef INC_SHT20_H_
#define INC_SHT20_H_
#include"stm32l4xx_hal.h"

/*chip 7-bits hardware address*/
#define SHT20_ADDR 0X44   /*GND*/

/*I2C protocol communication daaress*/
#define SHT20_ADDR_WR (SHT20_ADDR<<1)   /*write*/
#define SHT20_ADDP_RD ((SHT20_ADDR<<1)|0X01)  /*read*/

#define SHT20_DATA_SIZE 6  /*2B temp+1B CRC,2Bhumidity+1B CRC*/

typedef enum
{
   /*soft reset command*/
	SOFT_RESET_CMD=0X30A2,

	/*Measurement commands for single shot data acquisition Mode:
	 * Repeatability (low,medium and high) and clock stretching(enabled ordisabled)
 	 */
	HIGH_ENABLED_CMD =0x2C06,
	MEDIUM_ENABLED_CMD =0x2C0D,
	LOW_ENABLED_CMD =0x2C10,
	HIGH_DISABLED_CMD =0x2400,
	MEDIUM_DISABLED_CMD =0x240B,
	LOW_DIAABLED_CMD =0x2416,

	/*Measurement commands for periodic data acquisition Mode
	 * Data acquisition frequency:0.5,1,2,4 & 10 measurements per second,mps
	 */
	 HIGH_0_5_CMD =0x2032,
	 MEDIUM_0_5_CMD =0x2024,
	 LOW_0_5_CMD =0x202F,
	 HIGH_1_CMD =0x2130,
	 MEDIUM_1_CMD =0x2126,
	 LOW_1_CMD =0x212D,
	 HIGH_2_CMD =0x2236,
	 MEDIUM_2_CMD =0x2220,
	 LOW_2_CMD =0x222B,
	 HIGH_4_CMD =0x2334,
	 MEDIUM_4_CMD =0x2329,
	 LOW_4_CMD =0x2329,
	 HIGH_10_CMD =0x2737,
	 MEDIUM_10_CMD =0x2721,
	 LOW_10_CMD =0x272A,

	 /*Readout of measurement results for periodic mode*/
	 READOUT_FOR_PERIODIC_MODE = 0xE000,
}SHT20_CMD;

extern int SHT20_SampleData(float *temperature,float *humidity);
#endif /* INC_SHT20_H_ */


/*
 * sht20.h
 *
 *  Created on: May 10, 2023
 *      Author: lenovo lianxiang
 */

#ifndef INC_SHT20_H_
#define INC_SHT20_H_

#include "stm32l4xx_hal.h"


#define SHT20_ADDR 0x40

#define SHT20_ADDR_WR (SHT20_ADDR<<1)
#define SHT20_ADDR_RD ((SHT20_ADDR<<1) | 0x01)

#define TRH_FAIL_VAL      0xFFFFFFFF

enum
{
	TRIG_T_MEASUREMENT_HM    = 0xE3, // command trig. temp meas. hold master
	TRIG_RH_MEASUREMENT_HM   = 0xE5, // command trig. humidity meas. hold master
	TRIG_T_MEASUREMENT_POLL  = 0xF3, // command trig. temp meas. no hold master
	TRIG_RH_MEASUREMENT_POLL = 0xF5, // command trig. humidity meas. no hold master
	USER_REG_W               = 0xE6, // command writing user register
	USER_REG_R               = 0xE7, // command reading user register
	SOFT_RESET               = 0xFE  // command soft reset
};

extern uint32_t sht20_sample_TrH(uint32_t *temperature, uint32_t *humidity);

#endif /* INC_SHT20_H_ */

